package com.example.ywj.toutiao.compoents;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.ywj.toutiao.R;


public class Bottom_button extends Fragment {
    public RadioButton rbtn1,rbtn2,rbtn3,rbtn4;
    public RadioGroup radioGroup;
    public ViewPager vp;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.bottom_button, container, false);
    }

    @Override
    public void onStart() {
        vp = getActivity().findViewById(R.id.vp_fragment);
        radioGroup = getActivity().findViewById(R.id.radiogroup);
        vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }
            @Override
            public void onPageSelected(int i) {
                if(i==0){
                    //radioGroup.clearCheck();
                    radioGroup.check(R.id.radio0);
                }else if(i==1){
                    //radioGroup.clearCheck();
                    radioGroup.check(R.id.radio1);
                }else if(i==2){
                    //radioGroup.clearCheck();
                    radioGroup.check(R.id.radio2);
                }else if(i==3){
                    //radioGroup.clearCheck();
                    radioGroup.check(R.id.radio3);
             }
            }
            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
        super.onStart();
    }
}
